/*******************************************
  Jose Andres Lara Vecino

  Author       : $$Author: cainlara@gmail.com $$
  Last CheckIn : $$Date: 2012-08-22 18:35:06 +0000 (Wed, 22 Aug 2012) $$
  Revision     : $$Revision: 100 $$
*******************************************/

package api.impl;

import java.util.ArrayList;
import java.util.List;

import persistencia.TmSuite;
import utilidad.UtilConversor;
import api.ISuiteAPI;
import core.TestManagerException;
import dao.SuiteDao;
import frente.Suite;
import generico.GenericoAPI;

/**
 * Controlador de acciones para Suites.
 * <P>
 * Esta clase, administra la informacion 
 * persistente de los objetos tipo <code>Suite</code>.
 * 
 * @see SuiteDao
 * @see TmSuite
 * @see Suite
 * 
 * @author jose.lara 06.06.2012
 */
public final class SuiteAPI extends GenericoAPI implements ISuiteAPI {
    private static final long serialVersionUID = 2677171790161331035L;
    
    private SuiteDao dao    = null;
    
    public SuiteAPI() {
    }
    
    private SuiteDao getDao() {
        if(dao == null) {
            dao = new SuiteDao();
        }
        
        return dao;
    }
    
    @Override
    public List<Suite> getTodasSuites() throws TestManagerException {
        List<TmSuite> persistentes  = null;
        List<Suite> suites          = null;
        Suite suite                 = null;
        
        persistentes = getDao().getResultFindAll();
        
        if(persistentes != null) {
            suites = new ArrayList<Suite>();
            
            for(TmSuite persistente : persistentes) {
                suite = UtilConversor.convertir2Suite(persistente);
                
                if(suite != null) {
                    suites.add(suite);
                }
            }
        }
        
        return suites;
    }
}
